package com.wyx.jdbc.resultset;

import java.io.FileReader;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

/**2
 * @author 王艺锡
 * @version 1.0
 * ResultSet的使用
 */
public class ResultSet_ {
    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        Properties properties = new Properties();
        properties.load(new FileReader("src\\mysql.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");

        Class.forName(driver);

        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();
        String str = "select id,name,sex,borndate from actor";
        ResultSet resultSet = statement.executeQuery(str);

        //使用while循环遍历返回的查询结果
        while (resultSet.next()){
            int id = resultSet.getInt(1);//获取该行的第一列
            String name = resultSet.getString(2);//获取该行的第二列
            String sex = resultSet.getString(3);
            String birthday = resultSet.getString(4);
            System.out.println(id + "\t" + name + "\t" + sex + "\t" + birthday);
        }

        //关闭连接
        resultSet.close();
        statement.close();
        connection.close();


    }
}
